import { Node, Scene, UITransform, Widget } from "cc";
import { Mediator } from "../../mvcs/Mediator";

enum UIFormType {
    /** 大场景层：战斗 */
    ArenaLayer = 0,
    /** 装饰层 */
    UIDecoration = 1,
    /** 弹出窗口1 */
    UIView = 2,
    /** 弹出窗口2 */
    UIPopUp = 3,
    /** 引导层 */
    GuideLayer = 4,
    /** 提示层 */
    ToastLayer = 5,
    /** 最上层点击 */
    TouchLayer = 6,
};

export class BaseSceneMediator extends Mediator {

    private _uiLayer: Node = null;

    public onRegister(): void {
        super.onRegister();

        this.injector.mapValue('CurrentSceneMediator', this);

        let rootView = this.getView();
        this.initArana(rootView);
        this.initUIDecoration(rootView);
        this.initUIView(rootView);
        this.initUIPopup(rootView);
        this.initGuideLayer(rootView);
        this.initTouchLayer(rootView);
    }

    public onRemove(): void {

        super.onRemove();
    }

    public switchView(view: Node): void {
        view.parent = this._uiLayer;

        // replace top of stack
    }

    public pushView(view: Node): void {
        view.parent = this._uiLayer;

        // push stack
    }

    public popupView(): void {

    }

    public showToast(): void {

    }

    public onCloseView(): void {

    }

    public onClosePopupView(): void {

    }

    /**  private method */

    private initArana(rootView: Node) {

    }

    private initUIDecoration(rootView: Node) {

    }

    private initUIView(rootView: Node) {
        if (!this._uiLayer) {
            let sceneView: Scene = this.getView();
            let canvasNode: Node = sceneView.getChildByPath('Canvas');

            this._uiLayer = this.createNode('ui', canvasNode);
        }
    }

    private initUIPopup(rootView: Node) {

    }

    private initGuideLayer(rootView: Node) {

    }

    private initToastLayer(rootView: Node) {

    }

    private initTouchLayer(rootView: Node) {

    }

    private createNode(name: string, parent: Node): Node {
        let ret = new Node;
        ret.name = name;
        ret.parent = parent;

        ret.addComponent(UITransform);

        let widgetComp = ret.addComponent(Widget);
        widgetComp.isAlignLeft = true;
        widgetComp.isAlignRight = true;
        widgetComp.isAlignBottom = true;
        widgetComp.isAlignTop = true;
        widgetComp.left = 0;
        widgetComp.right = 0;
        widgetComp.top = 0;
        widgetComp.bottom = 0;
        return ret;
    }
}